<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>
    let strToWordFigure = (function () {
        let numArr = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];

        function getOne(index, after) {
            return index ? numArr[index] + (numArr[index] === '零' ? '' : after) : '';
        }

        function numStr(num) {
            if (num.length < 4)
                for (let i = 0, len = num.length; i < 4 - len; i++) {
                    num = '0' + num;
                }
            let nums = num.split('');
            let ret = getOne(nums[0], '千') + getOne(nums[1], '佰') + getOne(nums[2], '拾') + getOne(nums[3], '');
            ret = ret.replace(/\u96f6+/g, '零').replace(/\u96f6$/g, '');
            return ret;
        }

        return function (str) {
            let arr = str.replace(/(?=(\B)(\d{4})+$)/g, ',').split(',');
            let ret = [];
            if (arr.length === 3) {
                ret.unshift(numStr(arr[2]));
                ret.unshift(numStr(arr[1]) + (numStr(arr[1]) === '' ? '' : '万'));
                ret.unshift(numStr(arr[0]) + (numStr(arr[0]) === '' ? '' : '亿'));
            } else if (arr.length === 2) {
                ret.unshift(numStr(arr[1]));
                ret.unshift(numStr(arr[0]) + (numStr(arr[0]) === '' ? '' : '万'));
            } else if (arr.length === 1) {
                ret.unshift(numStr(arr[0]));
            }
            ret = ret.join('');
            return ret === '' ? '零' : ret.replace(/^\u96f6|/g, '');
        }
    })();
    console.log(strToWordFigure('101010001'));
    console.log(strToWordFigure('1234567890'));
    console.log(strToWordFigure('100010100'));
</script>
</body>
</html>